home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 090 / iau.arc / RFW.C < prev    next >
Encoding:
C/C++ Source or Header  |  1986-10-25  |  2.7 KB  |  134 lines

  1. #include <stdio.h>
  2. #include <hamdefs.h>
  3. extern int have_selected,drive_to_use,factor;
  4.  
  5. static char intlv_table[512];
  6. static char disk_buffer[17*512];
  7.  
  8. #define SECTORS 17
  9.  
  10. rfw()
  11. /* read, format, write */
  12. {
  13.     struct {unsigned int ax,bx,cx,dx,si,di,ds,es;}send,rec;
  14.     unsigned int cylinder,head,
  15.         cyl_max, head_max;
  16.     char temp[80];
  17.     unsigned percent;
  18.     
  19.     int pr,pc;
  20.     
  21.     percent=0;
  22.  
  23.     if(!have_selected) {
  24.     errmsg("You must select which drive to use.....");
  25.     return 0;
  26.     }
  27.  
  28.     build(factor);
  29.     segread(&send.si);
  30.     send.es=send.ds;
  31.     send.ax=0x0800;
  32.     send.bx=send.cx=0;
  33.     send.dx=drive_to_use;
  34.     if(1&sysint13(&send,&rec)) {
  35.     atputsa(2,25,"Unable to address hard disk(s)",NORMAL|HILITE);
  36.     beep();
  37.     return 1;
  38.     }
  39.     head_max=rec.dx>>8;
  40.     cyl_max=((rec.cx & 0xc0)<<2) + (rec.cx>>8);
  41.  
  42.     atputsa(3,10,"READ  FORMAT  WRITE   HEAD  CYLINDER",NORMAL|HILITE);
  43.     atputsha(-1,-1,"      Percent complete: ");
  44.     findcsr(&pr,&pc);
  45.     for(cylinder=0; cylinder <= cyl_max; cylinder++) {
  46.     locate(4,41);
  47.     sprintf(temp,"%d",cylinder);
  48.     vputs(temp);
  49.     percent=(((unsigned)100*cylinder)/cyl_max);
  50.     sprintf(temp,"%d",percent);
  51.     atputsha(pr,pc,temp);
  52.     for(head=0; head <= head_max; head++) {        
  53.         locate(4,33);
  54.         vputc(head+'0');
  55.         
  56.         /* read cylinder */
  57.         clrblk(4,10,4,30);
  58.         atputsha(4,11,"\315\315");
  59.         send.ax= 0x0200 + SECTORS;
  60.         send.bx= disk_buffer;
  61.         send.cx= (cylinder<<8) + ((cylinder&0x300)>>2) + 1;
  62.         send.dx= (head<<8) + drive_to_use;
  63.  
  64.         if(1 & sysint13(&send,&rec)) {
  65.         reset_disk();
  66.         continue;
  67.         }
  68.  
  69.         if(kbhit()) {
  70.         if(inkeyi()==3)
  71.             terminate();
  72.         clrkey();
  73.         }
  74.         
  75.         /* format cylinder: */
  76.  
  77.         clrblk(4,10,4,30);
  78.         atputsha(4,18,"\315\315");
  79.         send.ax=0x0500 + factor;
  80.         send.bx=intlv_table;
  81.  
  82.         if(1 & sysint13(&send,&rec)) {
  83.         reset_disk();
  84.         continue;
  85.         }
  86.  
  87.         /* write cylinder: */
  88.  
  89.         clrblk(4,10,4,30);
  90.         atputsha(4,25,"\315\315");
  91.         send.ax= 0x0300 + SECTORS;
  92.         send.bx= disk_buffer;
  93.  
  94.         if(1 & sysint13(&send,&rec)) {
  95.         reset_disk();
  96.         }
  97.     }
  98.     }
  99.     cursor(TRUE);
  100.     return 0;
  101. }
  102.  
  103. reset_disk()
  104. {
  105.     struct {int ax,bx,cx,dx,si,di,ds,es;}temp;
  106.     
  107.     temp.ax=0;
  108.     temp.dx=drive_to_use;
  109.     segread(&temp.si);
  110.     sysint13(&temp,&temp);
  111. }
  112.  
  113. build(factor)
  114. int factor;
  115. {
  116.     int i,cur;
  117.     
  118.     for(i=cur=0;i<17;i++,cur += factor) {
  119.     if(cur>17)
  120.         cur -= 17;
  121.     intlv_table[(2*cur)+1]=i+1;
  122.     }
  123. }
  124.  
  125. terminate()
  126. {
  127.     intrrest(0x23);
  128.     locate(22,2);
  129.     vputs("CTRL-C aborts the program at any time");
  130.     locate(23,0);
  131.     cursor(TRUE);
  132.     exit(0);
  133. }
  134.